package com.kermel.common.android;

import android.text.TextPaint;
import android.text.TextUtils;
import android.text.TextUtils.TruncateAt;
import android.widget.TextView;

public class TextViewUtils {

    public static CharSequence truncateText(TextView textView, CharSequence text) {
        CharSequence truncatedText = text;
        
        if (textView != null && text != null) {
            TextPaint textPaint = textView.getPaint();
            int availableWidth = textView.getMeasuredWidth();
            truncatedText = TextUtils.ellipsize(text, textPaint, availableWidth, TruncateAt.END);
        }
        
        return truncatedText;
    }
    
}
